<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="icon" type="text/css" href="icon.ico"/>
    <link rel="stylesheet" type="text/css" href="/shop/Public/Home/css/index.css" />
    <script src="/shop/Public/Home/js/jquery-1.10.1.min.js" type="text/javascript" charset="utf-8"></script>

    <script src="/shop/Public/Home/js/list.js" type="text/javascript" charset="utf-8"></script>
    <!--<script src="/shop/node_modules/hdjs/app/util.js"></script>-->
    <!--<script src="/shop/node_modules/hdjs/require.js"></script>-->
    <!--<script src="/shop/node_modules/hdjs/config.js"></script>-->
    <script src="/shop/Public/Home/js/layer.js"></script>

</head>

<body>
<!--头部开始-->
<div id="top">
    <!--头部灰条就开始-->
    <div class="topbox">
        <div class="main">
            <div class="topleft fl">
                <a href="javascript:;">欢迎来到<?php echo V("sp_system.0")['svalue'];?></a>
                <a href="#">设为首页</a>
                <a href="#">收藏本站</a>
                <!--<a href="#">帮助中心</a>-->
                <!--<a href="#" class='last'><i></i>手机商城</a>-->
            </div>
            <div class="topright fr">
                <div class="login fl">
                    <?php if(isset($_SESSION['uid'])): ?><span>欢迎您回来 <?php echo $_SESSION['uname']?><a href="<?php echo U('home/userinfo/info');?>">去个人中心</a></span>
                        <span><a href="<?php echo U('home/lg/exitlogin');?>">退出</a></span>
                        <?php else: ?>
                        <a href="<?php echo U('Home/Lg/login');?>">登录</a>
                        <a href="<?php echo U('Home/Lg/regest');?>">注册</a><?php endif; ?>
                </div>
                <span class="fl">|</span>

                <div class="fcode fl">

                    <a href="<?php echo U('home/userinfo/order');?>">我的订单</a>
                </div>
            </div>
        </div>
    </div>
    <!--头部灰条结束-->

    <!--logo区域开始-->
    <div class="logoRegion">
        <div class="main">
            <div class="logo">
                <a href="/shop/dami.html"><img width="185px" height="70px" src="<?php echo V('sp_system.3')['svalue'];?>"/></a>
            </div>
            <div class="seachRegion">
                <div class="seach fl">
                    <form action="<?php echo U('home/search/searchs');?>" method="post">
                        <input type="text" name="gname" class="seachtxt fl" value="O2+车载空气净化"/>
                        <input type="submit" class="btn" value=""/>
                    </form>
                    <p class="searchkey">
                        <?php if(is_array($hot)): $i = 0; $__LIST__ = $hot;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><a href="<?php echo U('home/goodinfo/index',['gid'=>$vo['gid']]);?>" style="display: inline-block;width: 160px;height:20px;overflow: hidden"><?php echo ($vo['gname']); ?></a><?php endforeach; endif; else: echo "" ;endif; ?>
                    </p>
                </div>

                <?php if((CONTROLLER_NAME != 'Order') AND (CONTROLLER_NAME != 'Car')): ?><div class="topshopcart fr">
                        <a href="<?php echo U('home/car/lists');?>" class="header-cart"><i></i>我的购物车<span class="cart-size">(<?php echo ($cars); ?>)</span></a>
                        <div class="cart-tips" style="width: 250px;padding-bottom: 10px">
                            <?php if(isset($_SESSION['uid'])): ?><ul id="car_ul" style="background: #fff;width: 250px;padding: 0px;margin: 0px;padding-bottom: 10px">
                                </ul>
                                <?php else: ?>
                                请
                                <a href="<?php echo U('home/lg/login');?>">登录</a>后查看您的购物车。<?php endif; ?>
                        </div>
                    </div><?php endif; ?>


            </div>
            <script>
                //                购物车AJAX异步
                $('.header-cart').mouseenter(function(){
                    uid="<?php echo session('uid');?>";
                    if(uid){
                        var str='';
                        var count=0;
                        $.post("<?php echo U('home/car/finAjxgood');?>",{uid:uid}, function (res) {
                            if($.isEmptyObject(res)){
//                            alert(444);
                                $('#car_ul').html('购物车中没有一件商品，快去购物吧');return false;
                            }else {
                                console.log(res);
                                $.each(res, function (k, v) {
                                    count = count + parseInt(v.count);
                                    str += '<li style="width: 250px;padding: 0px;margin: 0px;height:50px;line-height:20px;text-align: left;border-bottom: 2px dashed orangered;padding-bottom: 15px;margin-top: 8px">';
                                    str += '<a href="" style="display:block;width: 50px;height:60px;float: left;margin-left: 5px;">';
                                    str += '<img width="50px" height="50px" src="' + v.thumb + '" alt=""></a>';
                                    str += '<a href="" style="display: block;width: 80px;height: 60px;float:left;overflow: hidden;margin-left: 15px">' + v.gname + '</a>';
                                    str += '<a style="display: block;width:90px;height: 60px;float:left;overflow: hidden;margin-left: 5px">￥' + v.priced + ' X ' + v.count + '<br/><br/><span ugid="'+v.ugid+'" class="delgood" style="padding: 4px 4px;background: orange;cursor: pointer">删除</span></a></li>';
                                })
//                        alert(str);
                                str += '<li style="line-height: 20px;padding-top: 10px;;margin: 0px"> <a href="/shop/home/car/lists" style="background: orangered;color:#fff;line-height: 20px;padding: 5px;margin: 0px">去结算</a> </li>';
                                $('.cart-size').html('(' + count + ')');
                                $('#car_ul').html(str);
                            }
                        });
                    }

                })
                //购物车删除按钮删除购物车中的物品
                $('#car_ul').on('click','.delgood',function(){
                    var ugid=$(this).attr('ugid');
                    that=$(this);
                    //异步后台删除
                    $.post("<?php echo U('home/car/ajaxdelgood');?>",{ugid:ugid},function(res){
                        if(res.valid){
                            location.reload();
                        }
                    },'json');
                });

            </script>
        </div>
    </div>
    <!--logo区域结束-->
    <div class="clear"></div>
    <!--导航开始-->
    <div class="navbox">
        <div class="main">
            <h5 class="fl"><a href="<?php echo U('Home/index/index');?>"><i></i>全部智能酷品</a></h5>
            <ul class="menu fl">
                <?php if(is_array($nature)): foreach($nature as $key=>$vo): ?><li class="menulist">
                    <a href=""><?php echo ($vo['nname']); ?></a>
                    <div class="menuHiden">
                        <ul class="product">
                            <?php if(is_array($vo['goods'])): foreach($vo['goods'] as $key=>$voo): ?><li>
                                <a href="<?php echo U('home/goodinfo/index',['gid'=>$voo['gid']]);?>"><img width="150px" height="157px" src="<?php echo ($voo['thumb']); ?>" alt="" /></a>
                            </li><?php endforeach; endif; ?>
                        </ul>
                    </div>
                </li><?php endforeach; endif; ?>

            </ul>

        </div>

    </div>
    <!--导航结束-->
    <div class="clear"></div>

</div>
<!--头部结束-->
<!--中间开始-->

<div id="content">
	<form action="" onsubmit="return pay()" method="post">
		<div class="car main">
			<div class="carshop">
				<div class="cartitle">
					<div class="carcheck">
						<div class="checkbox">
							<span class="check checkon" id="allcheck"></span>
						</div>
						全选</div>
					<div class="carname">商品名称</div>
					<div class="carmoney">单价</div>
					<div class="carnum">数量</div>
					<div class="carcount">小计</div>
					<div class="carhandle">操作</div>
				</div>
				<?php if(is_array($goods)): foreach($goods as $key=>$vo): ?><div class="shopcontent">
					<input type="hidden" disabled name="gid[]" value="<?php echo ($vo['gid']); ?>">
					<input type="hidden" disabled name="pcid[]" value="<?php echo ($vo['pcid']); ?>">
					<div class="shopcheck">
						<div class="checkbox">
						<span class="check checkon" ch="1"></span>
						<input type="checkbox"  class="checkhide"/>

					     </div>
					</div>
					<div class="shopname" >
						<div class="carimg">
							<a href=""><img width="50px" height="70px" src="<?php echo ($vo['thumb']); ?>"/></a>
						</div>
						<p>
							<a href="#" style="font-size: 14px"><?php echo ($vo['gname']); ?>&nbsp;&nbsp;</a>
							<span><?php echo ($vo['digest']); ?>||<?php echo ($vo['pstyle']); ?></span>
						</p>
					</div>
					<div class="shopmoney"><?php echo ($vo['priced']); ?></div>
					<div class="shopnum">
						<a href="javascript:;" gid="<?php echo ($vo['gid']); ?>" pcid="<?php echo ($vo['pcid']); ?>" class="num_l">-</a>
						<input class="count" type="text" readonly value="<?php echo ($vo['count']); ?>" />
						<a href="javascript:;" gid="<?php echo ($vo['gid']); ?>" pcid="<?php echo ($vo['pcid']); ?>" stock="<?php echo ($vo['stock']); ?>" class="num_r">+</a>
					</div>
					<div class="shopcount">元</div>
					<div class="shophandle"><span  pcid="<?php echo ($vo['pcid']); ?>" gid="<?php echo ($vo['gid']); ?>" >x</span></div>
				</div><?php endforeach; endif; ?>
			</div>
			<div class="jiesuan">
				<div class="jixu"><a href="">继续购物</a></div>
				<div class="gongji">共计<span>10</span>件商品</div>
				<div class="heji">合计<span>100.00</span>元</div>
				<div class="gou"><input type="submit" value="去结算"/></div>
			</div>
			<script>
				$(function(){
					//防止用户一直点+
					var sta=1;
					setInterval(move,2000);
					function move(){
                       sta=0;
						setTimeout(function(){
							sta=1;
						},2000);
					}
					//点击删除商品时
					$('.shophandle span').click(function(){
						var gid=$(this).attr('gid');
						var pcid=$(this).attr('pcid');
//						alert(gid);
						$.post("<?php echo U('home/car/delgood');?>",{gid:gid,pcid:pcid},function(res){

						},'json');
					})
					//计算总价格，总数量
					var zongjia=0;
					var zongshu=0;
					for(var i=0;i<$(".shopcontent").length;i++){
                       var price=parseFloat($('.shopcontent').eq(i).find('.shopmoney').text());
						var count=parseInt($('.shopcontent').eq(i).find('.count').val());
						var jiage=price*count;
						$('.shopcount').eq(i).text(jiage);
						zongjia=zongjia+jiage;
						zongshu=zongshu+count;
//						alert(zongshu);
					}
					$('.jiesuan').find('.heji').find('span').text(zongjia);
					$('.jiesuan').find('.gongji').find('span').text(zongshu);

					//点击加的时候小计同步增加
					$('.car .carshop .shopcontent .shopnum a.num_r').click(function(){
//                         alert(sta);
						//获取该商品的gid
						var gid=parseInt($(this).attr('gid'));
						//获取该商品的pcid
						var pcid=parseInt($(this).attr('pcid'));
						var stock=parseInt($(this).attr('stock'));
//						alert (stock);
						if(sta){
							var danjia=parseInt($(this).closest('.shopnum').prev().text());
							var count=parseInt($(this).closest('.shopnum').next().text());
							var num=$(this).prev().val();
							if(num>=0){
								num++;
								$(this).prev().val(num);
								//$(this).closest('.shopnum').next().text(num*danjia+'元');
								//$('.heji span').text(setcount().n+'元');
							}
							if(num>stock){
								alert('库存不够了');
								$(this).prev().val(stock);
								//$(this).closest('.shopnum').next().text(100*danjia+'元');
							}
//							alert(sta);
							aa=parseFloat($(this).parent().siblings('.shopcount').text())+ parseFloat($(this).parent().siblings('.shopmoney').text());
							aa=aa.toFixed(2);
							$(this).parent().siblings('.shopcount').text(aa);
							//总价增加
							zongjia=zongjia+parseFloat($(this).parent().siblings('.shopmoney').text());
							$('.jiesuan').find('.heji').find('span').text(zongjia);
							//总数量增加
							zongshu=zongshu+1;
//						alert(2);
//						alert(zongshu);
							$('.jiesuan').find('.gongji').find('span').text(zongshu);
							//发异步，将数据库商品的数量加1
							$.post("<?php echo U('home/car/ajaxAddgood');?>",{gid:gid,pcid:pcid}, function (res) {

							},'json');
						}
						sta=0;

					});


                    //点击减的时候小计同步减少
					$('.car .carshop .shopcontent .shopnum a.num_l').click(function(){
						var counts=parseInt($(this).siblings('.count').val());
						if(counts<=1){
                          return false;
						};

						var danjia=parseInt($(this).closest('.shopnum').prev().text());
						var count=parseInt($(this).closest('.shopnum').next().text());
						var num=$(this).next().val();
						if(num<=1){
							alert('小于1咋买啊');
							$(this).next().val(1);
						}
						if(num>1){
							num--;
							$(this).next().val(num);
						}
						aa=parseFloat($(this).parent().siblings('.shopcount').text())- parseFloat($(this).parent().siblings('.shopmoney').text());
						aa=aa.toFixed(2);
						$(this).parent().siblings('.shopcount').text(aa);
						//总价减少
						zongjia=zongjia-parseFloat($(this).parent().siblings('.shopmoney').text());
//						zongjia=zongjia.toFixed(2);
						$('.jiesuan').find('.heji').find('span').text(zongjia);
						//总数量减少
						zongshu=zongshu-1;
						$('.jiesuan').find('.gongji').find('span').text(zongshu);
						//发异步将用户数据库中的该商品的数量减1
						//获取该商品的gid
						var gid=parseInt($(this).attr('gid'));
						//获取该商品的pcid
						var pcid=parseInt($(this).attr('pcid'));
						$.post("<?php echo U('home/car/ajaxreduce');?>",{gid:gid,pcid:pcid},function(res){

						},'json');
					});
//					alert(zongjia);
					//计算多少件商品
				})
			</script>
		</div>
	</form>
</div>

<script>
	//点击去结算时
	function pay(){
//		alert(333);
		 var count=$(".checkbox .check[ch='1']").length;
		if(count==0){
			layer.msg('请选择要付款的商品', function(){
			});
			return false;
		}
		$.each($(".checkbox .check[ch='1']"),function(){
//			alert(33);
			$(this).parents('.shopcontent').find('input').removeAttr('disabled');
		})
		var data=$('form').serialize();
//		alert(data.unseri);
//		location.href="/shop/index.php/home/order/pay/data/"+data;
		$.post("<?php echo U('home/order/pay');?>",data,function(res){
          if(res){
			  location.href="<?php echo U('home/order/pay',['paystatus'=>1]);?>";
		  }
		});

 		return false;
	}

</script>
<!--中间结束-->
<!--尾部开始-->
<div class="mod-footer">
    <div class="foot-bannerw">
        <div class="foot-banner clearfix">
            <div class="banner-item">
                <a href="#" target="_blank" data-monitor="home_foot_days7"><i class="icon1">7</i>7天无理由退货</a>
            </div>
            <div class="banner-item">
                <a href="#" target="_blank" data-monitor="home_foot_days15"><i class="icon2">15</i>15天免费换货</a>
            </div>
            <div class="banner-item"><i class="icon3">包</i>满99元包邮</div>
            <div class="banner-item">
                <a href="#" target="_blank" data-monitor="home_foot_moblie"><i class="icon4">服</i>手机特色服务</a>
            </div>
        </div>
    </div>

    <div class="foot-containerw">
        <div class="foot-container clearfix">
            <dl class="foot-con">
                <dt data-monitor="home_foot_freshman">联系作者</dt>
                <dd data-monitor="home_help_freshman">
                    <a target="_blank" href="javascript:;" rel="nofollow">YD</a>
                </dd>
            </dl>
            <dl class="foot-con">
                <dt data-monitor="home_foot_help">作者电话</dt>
                <dd data-monitor="home_help_help">
                    <a target="_blank" href="#">13517224196</a>
                </dd>
            </dl>
            <dl class="foot-con">
                <dt data-monitor="home_foot_guide">联系邮箱</dt>
                <dd data-monitor="home_help_guide">
                    <a target="_blank" href="#" rel="nofollow">yedong_163_hubei.com</a>
                </dd>
            </dl>
            <style>

            </style>
            <dl class="foot-con">
                <dt data-monitor="home_foot_tuiguang">友情链接</dt>

                <?php if(is_array($links)): foreach($links as $key=>$vo): ?><dd data-monitor="home_help_try">
                        <a target="_blank" href="<?php echo ($vo['lurl']); ?>" rel="nofollow"><?php echo ($vo['lname']); ?></a>
                    </dd><?php endforeach; endif; ?>

            </dl>
            <dl class="foot-con">
                <dt data-monitor="home_foot_try">关注大米商城</dt>
                <dd data-monitor="home_help_try">
                    <a target="_blank" href="#" rel="nofollow">360商城大事记</a>
                </dd>
            </dl>

        </div>
    </div>
    <div class="footer-copyright"><?php echo V("sp_system.0")['svalue'];?> <?php echo V('sp_system.2')['svalue'];?>
        <?php echo V('sp_system.1')['svalue'];?>
    </div>
</div>
<!--尾部结束-->

<!--右边底部返回顶部-->
<div class="slidebar" id="slidebar">
    <ul>
        <li class="topback">
            <a href="javascript:;"></a>
        </li>
    </ul>
</div>
<!--右边底部返回顶部结束-->

</body>

</html>